package com.lemon.core.mqapi.producer;

import com.lemon.core.common.lang.util.SystemEnvUtils;

/**
 * @author lemon
 * @ClassName MqSender
 * @desc
 * @Date 2018/11/2 18:12
 * @Version 1.0
 **/
public class MqSender extends RabbitMQImpl {

    public static MqSender mqSender = null;

    public static MqSender getInstance() {
        if (mqSender == null) {
            synchronized (MqSender.class) {
                if (mqSender == null) {
                    initDefaultMqSender();
                }
            }
        }
        return mqSender;
    }

    public static MqSender getInstance(String host, Integer port, String username, String password, String virtualHost) {
        if (mqSender == null) {
            synchronized (MqSender.class) {
                if (mqSender == null) {
                    mqSender = new MqSender(host, port, username, password, virtualHost);
                }
            }
        }
        return mqSender;
    }

    private static void initDefaultMqSender() {
        if (SystemEnvUtils.IS_PROD) {
            mqSender = new MqSender("127.0.0.1", 5672, "guest", "guest", "/");
        } else {
            mqSender = new MqSender("127.0.0.1", 5672, "guest", "guest", "/");
        }
    }

    private MqSender(String host, Integer port, String username, String password, String virtualHost) {
        super(host, port, username, password, virtualHost);
    }
}
